package org.devbg.academy.corejava.shop.db.daos;

import java.util.List;

import org.hibernate.Query;

import org.devbg.academy.corejava.shop.db.entities.Order;
import org.devbg.academy.corejava.shop.db.entities.OrderItem;
import org.devbg.academy.corejava.shop.db.utils.HibernateSessionManager;
import org.hibernate.Session;

public class OrderItemDAO extends BaseDAO {

	@SuppressWarnings("unchecked")
	public OrderItemDAO() {
		super(OrderItem.class);
	}
	
	@SuppressWarnings("unchecked")
	public List<OrderItem> findByOrder(Order order) {
		HibernateSessionManager.openSession();
		Session hbSession = HibernateSessionManager.getCurrentSession();
		Query findByOrderQuery = hbSession.createQuery("from OrderItem o " +
				"where o.Order.OrderId = :orderId");
		findByOrderQuery.setLong("orderId", order.getId());
		List<OrderItem> result = findByOrderQuery.list();
		return result;
	}

}
